(function(){"use strict";BX.namespace("BX.UI");BX.UI.AccessRights.ColumnItem=function(e){this.grid=e.grid?e.grid:null;this.id=e.id?e.id:null;this.type=e.type?e.type:null;this.text=e.text?e.text:null;this.hint=e.hint?e.hint:null;this.variables=e.variables?e.variables:[];this.userGroup=e.userGroup;this.access=e.access?e.access:null;this.currentParam=e.currentParam;this.controller=e.controller?e.controller:null;this.openPopupEvent=e.openPopupEvent;this.popupContainer=e.popupContainer;this.accessCodes=e.accessCodes?e.accessCodes:[];this.isModify=false;this.popupHelper=null;this.popupHint=null;this.popupTimer=null;this.popupConfirm=null;this.popupUsers=null;this.identificator="col-"+Math.random();this.updatedUsers=[];this.layout={container:null,variablesValue:null,role:null,roleInput:null,roleValue:null,changer:null,switcher:null,controller:null,controllerMenu:null,controllerLink:null,addUserToRole:null,members:null};this.column=e.column;this.popupMenu=null;this.switcher=null;this.bindEvents()};BX.UI.AccessRights.ColumnItem.prototype={bindEvents:function(){if(this.type==="role"){BX.bind(window,"click",function(e){if(e.target===this.layout.role||BX.findParent(e.target,{className:"ui-access-rights-role"})){return}this.updateRole();this.offRoleEditMode()}.bind(this))}if(this.type==="toggler"){BX.addCustomEvent("BX.UI.AccessRights:reset",this.offChanger.bind(this));BX.addCustomEvent("BX.UI.AccessRights:refresh",this.refreshStatus.bind(this))}if(this.type==="members"){BX.addCustomEvent("BX.UI.AccessRights:addToAccessCodes",this.addToAccessCodes.bind(this));BX.addCustomEvent("BX.UI.AccessRights:removeFromAccessCodes",this.removeFromAccessCodes.bind(this));BX.addCustomEvent("BX.UI.AccessRights:reset",this.resetNewMembers.bind(this));BX.addCustomEvent("BX.UI.AccessRights:refresh",this.resetNewMembers.bind(this))}},getTextNode:function(){return BX.create("div",{props:{className:"ui-access-rights-column-item-text"},attrs:{"data-id":this.id},text:this.text,events:{mouseenter:function(){if(this.type==="title"){this.adjustPopupHelper()}}.bind(this),mouseleave:function(){if(this.popupHelper){this.popupHelper.close()}if(this.popupTimer){clearTimeout(this.popupTimer)}}.bind(this)}})},getHint:function(){if(!this.layout.hint&&this.hint){this.popupHint=BX.PopupWindowManager.create(null,null,{className:"ui-access-rights-popup-pointer-events",autoHide:true,darkMode:true,content:this.hint,maxWidth:280,offsetTop:0,offsetLeft:8,angle:true,animation:"fading-slide"});this.layout.hint=new BX.create("a",{props:{className:"ui-access-rights-column-item-notify"},events:{mouseover:function(){this.popupHint.setBindElement(this.layout.hint);this.popupHint.show()}.bind(this),mouseleave:function(){this.popupHint.close()}.bind(this)}})}return this.layout.hint},getChanger:function(){if(!this.layout.changer){this.layout.changer=BX.create("div",{props:{className:"ui-access-rights-column-item-changer"}})}return this.layout.changer},adjustChanger:function(){if(!this.isModify){this.isModify=true}else{this.isModify=false}if(this.layout.changer){this.layout.changer.classList.toggle("ui-access-rights-column-item-changer-on")}},refreshStatus:function(){this.layout.changer.classList.remove("ui-access-rights-column-item-changer-on")},offChanger:function(){if(this.isModify){this.layout.changer.classList.remove("ui-access-rights-column-item-changer-on");if(this.isModify){this.switcher.isChecked()?this.switcher.check(false):this.switcher.check(true)}setTimeout(function(){this.layout.changer.classList.remove("ui-access-rights-column-item-changer-on")}.bind(this))}},addToAccessCodes:function(e){var t=e.data;if(t.columnId!==this.identificator){return}var s=Object.keys(t.accessCodes)[0];var i=t.accessCodes[s].toUpperCase();this.userGroup.accessCodes=Object.keys(this.accessCodes);var o=t.item;if(typeof o!=="undefined"&&Object.keys(o).length){this.userGroup.members[s]={id:o.entityId,name:o.name,avatar:o.avatar,url:"",new:true,type:i.toLowerCase()};this.updateMembers()}this.userGroup.accessCodes=[];for(var s in this.userGroup.members){this.userGroup.accessCodes[s]=this.userGroup.members[s].type}},removeFromAccessCodes:function(e){var t=e.data;if(t.columnId!==this.identificator){return}var s=Object.keys(t.accessCodes)[0];delete this.userGroup.members[s];this.updateMembers();this.userGroup.accessCodes=[];for(var s in this.userGroup.members){this.userGroup.accessCodes[s]=this.userGroup.members[s].type}},getToggler:function(){if(!this.switcher){var e=this;this.switcher=new BX.UI.Switcher({size:"small",checked:this.currentParam==="1",handlers:{checked:function(){BX.onCustomEvent(window,"BX.UI.AccessRights.ColumnItem:accessOn",e)},unchecked:function(){BX.onCustomEvent(window,"BX.UI.AccessRights.ColumnItem:accessOff",e)},toggled:function(){this.adjustChanger();BX.onCustomEvent(window,"BX.UI.AccessRights.ColumnItem:update",e)}.bind(this)}})}return this.switcher.getNode()},getVariables:function(){if(!this.layout.variablesValue){this.layout.variablesValue=BX.create("div",{props:{className:"ui-access-rights-column-item-text-link"},text:this.variables[0].title,events:{click:this.showVariablesPopup.bind(this)}})}return this.layout.variablesValue},getController:function(){if(!this.layout.controller){this.layout.controller=BX.create("div",{props:{className:"ui-access-rights-column-item-controller"},children:[this.layout.controllerLink=BX.create("div",{props:{className:"ui-access-rights-column-item-controller-link"},text:BX.message("JS_UI_ACCESSRIGHTS_CREATE_ROLE")}),this.layout.controllerMenu=BX.create("div",{props:{className:"ui-access-rights-column-item-controller-link"},text:BX.message("JS_UI_ACCESSRIGHTS_COPY_ROLE"),events:{click:function(){this.getPopupMenu(this.grid.getUserGroups()).show()}.bind(this)}})]});this.layout.controllerLink.addEventListener("click",function(){BX.onCustomEvent(window,"BX.UI.AccessRights.ColumnItem:addRole",[{id:"0",title:BX.message("JS_UI_ACCESSRIGHTS_ROLE_NAME"),accessRights:[],members:[],accessCodes:[],type:"role"}]);BX.onCustomEvent(window,"BX.UI.AccessRights.ColumnItem:update",this);this.grid.lock()}.bind(this))}return this.layout.controller},getPopupMenu:function(e){if(!e){return}var t=[];e.map(function(e){t.push({text:BX.util.htmlspecialchars(e.title),onclick:function(){var t=Object.assign([],e.accessRights);var s=Object.assign([],e.accessCodes);BX.onCustomEvent(window,"BX.UI.AccessRights.ColumnItem:copyRole",[{id:"0",title:BX.message("JS_UI_ACCESSRIGHTS_ROLE_NAME"),accessRights:t,accessCodes:s,type:"role",members:e.members}]);BX.onCustomEvent(window,"BX.UI.AccessRights.ColumnItem:update",this);this.popupMenu.destroy()}.bind(this)})}.bind(this));return this.popupMenu=new BX.PopupMenuWindow(null,this.layout.controllerMenu,t,{events:{onPopupClose:function(){this.popupMenu.destroy();this.popupMenu=null}.bind(this)}})},showVariablesPopup:function(){var e=[];this.variables.map((function(t){e.push({id:t.id,text:t.title})}));BX.PopupMenu.show("ui-access-rights-column-item-popup-variables",this.layout.variablesValue,e,{autoHide:true,events:{onPopupClose:function(){BX.PopupMenu.destroy("ui-access-rights-column-item-popup-variables")}.bind(this)}})},getRole:function(){if(!this.layout.role){BX.addCustomEvent("BX.UI.AccessRights:preservation",this.updateRole.bind(this));BX.addCustomEvent("BX.UI.AccessRights:preservation",this.offRoleEditMode.bind(this));this.layout.role=BX.create("div",{props:{className:"ui-access-rights-role"},children:[this.layout.roleInput=BX.create("input",{props:{type:"text",className:"ui-access-rights-role-input",value:this.text,placeholder:BX.message("JS_UI_ACCESSRIGHTS_ROLE_NAME")},events:{keydown:function(e){if(e.keyCode===13){this.updateRole();this.offRoleEditMode()}}.bind(this),input:function(){this.grid.getButtonPanel().show()}.bind(this)}}),this.layout.roleValue=BX.create("div",{props:{className:"ui-access-rights-role-value",innerText:this.text}}),BX.create("div",{props:{className:"ui-access-rights-role-controls"},children:[BX.create("div",{props:{className:"ui-access-rights-role-edit"},events:{click:this.onRoleEditMode.bind(this)}}),BX.create("div",{props:{className:"ui-access-rights-role-remove"},events:{click:this.showPopupConfirm.bind(this)}})]})]})}return this.layout.role},showPopupConfirm:function(){var e=this;if(!this.popupConfirm){this.popupConfirm=BX.PopupWindowManager.create(null,this.layout.container,{width:250,overlay:true,contentPadding:10,content:BX.message("JS_UI_ACCESSRIGHTS_POPUP_REMOVE_THIS_ROLE"),animation:"fading-slide"});this.popupConfirm.setButtons([new BX.PopupWindowCustomButton({text:BX.message("JS_UI_ACCESSRIGHTS_POPUP_REMOVE"),className:"ui-btn ui-btn-sm ui-btn-primary",events:{click:function(){e.popupConfirm.close();BX.onCustomEvent(window,"BX.UI.AccessRights.ColumnItem:removeRole",e)}}}),new BX.PopupWindowCustomButton({text:BX.message("JS_UI_ACCESSRIGHTS_POPUP_CANCEL"),className:"ui-btn ui-btn-sm ui-btn-link",events:{click:function(){e.popupConfirm.close()}}})])}this.popupConfirm.show()},onRoleEditMode:function(){this.layout.role.classList.add("ui-access-rights-role-edit-mode");this.layout.roleInput.focus()},updateRole:function(){if(this.layout.roleValue.innerHTML===this.layout.roleInput.value||this.layout.roleInput.value===""){return}this.text=this.layout.roleInput.value;this.userGroup=this.column.getUserGroup();this.layout.roleValue.innerText=this.layout.roleInput.value;BX.onCustomEvent(window,"BX.UI.AccessRights.ColumnItem:updateRole",this)},offRoleEditMode:function(){this.layout.role.classList.remove("ui-access-rights-role-edit-mode")},validateVariables:function(){if(typeof this.userGroup.accessCodes==="undefined"){this.userGroup.accessCodes=[]}},getMembers:function(){if(!this.layout.members){var e=this.userGroup.members||{};var t=document.createDocumentFragment();var s=0;this.validateVariables();Object.keys(e).reverse().forEach((function(i){s++;if(s<7){var o=e[i];var r=o.new?" ui-access-rights-members-item-new":"";var n=" ui-icon-common-user";if(o.type==="groups"){n=" ui-icon-common-user-group"}if(o.type==="sonetgroups"){n=" ui-icon-common-company"}if(o.type==="usergroups"){n=" ui-icon-common-user-group"}t.appendChild(BX.create("div",{props:{className:"ui-access-rights-members-item"+r},children:[o.avatar?BX.create("a",{props:{className:"ui-access-rights-members-item-avatar",title:o.name},style:{backgroundImage:"url("+encodeURI(o.avatar)+")",backgroundSize:"cover"}}):null,!o.avatar?BX.create("a",{props:{className:"ui-icon ui-icon-xs"+n,title:o.name,innerHTML:"<i></i>"}}):null]}))}}));this.getAddUserToRole();t.appendChild(this.layout.addUserToRole);this.layout.members=BX.create("div",{props:{className:"ui-access-rights-members"},children:[t],events:{click:this.adjustPopupUserControl.bind(this)}})}return this.layout.members},resetNewMembers:function(){var e=this.layout.members.querySelectorAll(".ui-access-rights-members-item-new");e.forEach((function(e){e.classList.remove("ui-access-rights-members-item-new")}))},adjustPopupUserControl:function(){var e=[];var t=[];var s=[];var i=[];for(var o in this.userGroup.members){this.userGroup.members[o].key=o;if(this.userGroup.members[o].type==="users"){e.push(this.userGroup.members[o])}if(this.userGroup.members[o].type==="groups"){t.push(this.userGroup.members[o])}if(this.userGroup.members[o].type==="usergroups"){t.push(this.userGroup.members[o])}if(this.userGroup.members[o].type==="departments"){s.push(this.userGroup.members[o])}if(this.userGroup.members[o].type==="sonetgroups"){i.push(this.userGroup.members[o])}}var r=[];for(var n in this.userGroup.members){r.push(this.userGroup.members[n])}if(r.length===0){this.showUserSelectorPopup();return}this.getUserPopup(e,t,s,i).show()},getAddUserToRole:function(){if(!this.layout.addUserToRole){this.layout.addUserToRole=BX.create("span",{props:{className:"ui-access-rights-members-item ui-access-rights-members-item-add"},attrs:{"bx-data-column-id":this.identificator}})}return this.layout.addUserToRole},updateMembers:function(){this.layout.members.parentNode.removeChild(this.layout.members);this.layout.members=null;this.layout.container.appendChild(this.getMembers());this.grid.getButtonPanel().show()},getUserPopupTogglerGroup:function(e,t){var s=BX.create("div",{props:{className:"ui-access-rights-popup-toggler-content ui-access-rights-popup-toggler-content-"+t}});var i=this;var o="";if(t==="users"){o="ui-icon-common-user"}if(t==="groups"){o="ui-icon-common-user-group"}if(t==="sonetgroups"||t==="departments"){o=" ui-icon-common-company"}e.forEach((function(e){s.appendChild(BX.create("div",{props:{className:"ui-access-rights-popup-toggler-content-item"},children:[e.avatar?BX.create("a",{props:{className:"ui-access-rights-popup-toggler-content-item-userpic",title:e.name},style:{backgroundImage:"url("+encodeURI(e.avatar)+")",backgroundSize:"cover"}}):null,!e.avatar?BX.create("a",{props:{className:"ui-icon ui-icon-sm "+o,title:e.name,innerHTML:"<i></i>"},style:{margin:"5px 10px"}}):null,BX.create("div",{props:{className:"ui-access-rights-popup-toggler-content-item-name"},text:e.name}),BX.create("div",{props:{className:"ui-access-rights-popup-toggler-content-item-remove"},text:BX.message("JS_UI_ACCESSRIGHTS_REMOVE"),events:{click:function(){i.userGroup.accessCodes.splice(i.userGroup.accessCodes.indexOf(e.key),1);delete i.userGroup.accessCodes[e.key];delete i.userGroup.members[e.key];var t=BX.findParent(this,{className:"ui-access-rights-popup-toggler-content"});t.removeChild(this.parentNode);i.updateMembers();i.grid.getButtonPanel().show()}}})]}))}));return s},getUserPopup:function(e,t,s,i){if(!this.popupUsers){e=e||[];t=t||[];s=s||[];i=i||[];BX.create("div",{props:{className:"ui-access-rights-popup-toggler-content-item"}});var o=BX.create("div",{props:{className:"ui-access-rights-popup-toggler"},children:[BX.create("div",{props:{className:"ui-access-rights-popup-toggler-title"},children:[t.length>0?BX.create("div",{props:{className:"ui-access-rights-popup-toggler-title-item ui-access-rights-popup-toggler-title-item-active"},attrs:{"data-role":"ui-access-rights-popup-toggler-content-groups"},text:BX.message("JS_UI_ACCESSRIGHTS_USER_GROUPS"),events:{click:function(){n(this);r(this)}}}):null,s.length>0?BX.create("div",{props:{className:"ui-access-rights-popup-toggler-title-item"},attrs:{"data-role":"ui-access-rights-popup-toggler-content-departments"},text:BX.message("JS_UI_ACCESSRIGHTS_DEPARTMENTS"),events:{click:function(){n(this);r(this)}}}):null,e.length>0?BX.create("div",{props:{className:"ui-access-rights-popup-toggler-title-item"},attrs:{"data-role":"ui-access-rights-popup-toggler-content-users"},text:BX.message("JS_UI_ACCESSRIGHTS_STAFF"),events:{click:function(){n(this);r(this)}}}):null,i.length>0?BX.create("div",{props:{className:"ui-access-rights-popup-toggler-title-item"},attrs:{"data-role":"ui-access-rights-popup-toggler-content-sonetgroups"},text:BX.message("JS_UI_ACCESSRIGHTS_SOCNETGROUP"),events:{click:function(){n(this);r(this)}}}):null,BX.create("div",{props:{className:"ui-access-rights-popup-toggler-title-slicker"}})]}),t.length>0?this.getUserPopupTogglerGroup(t,"groups"):null,s.length>0?this.getUserPopupTogglerGroup(s,"departments"):null,e.length>0?this.getUserPopupTogglerGroup(e,"users"):null,i.length>0?this.getUserPopupTogglerGroup(i,"sonetgroups"):null,BX.create("div",{props:{className:"ui-access-rights-popup-toggler-footer"},children:[BX.create("div",{props:{className:"ui-access-rights-popup-toggler-footer-link"},text:BX.message("JS_UI_ACCESSRIGHTS_ADD"),events:{click:function(e){this.popupUsers.close();this.showUserSelectorPopup();BX.PreventDefault(e)}.bind(this)}})]})]});var r=function(e){if(!BX.type.isDomNode(e)){e=o.querySelector(".ui-access-rights-popup-toggler-title-item-active")}var t=o.querySelector(".ui-access-rights-popup-toggler-title-slicker");t.style.left=e.offsetLeft+"px";t.style.width=e.offsetWidth+"px"};var n=function(e){var t=o.querySelectorAll(".ui-access-rights-popup-toggler-title-item");var s=o.querySelectorAll(".ui-access-rights-popup-toggler-content");var i=o.querySelector("."+e.getAttribute("data-role"));t.forEach((function(e){e.classList.remove("ui-access-rights-popup-toggler-title-item-active")}));s.forEach((function(e){e.style.display="none"}));i.style.display="block";e.classList.add("ui-access-rights-popup-toggler-title-item-active")};this.popupUsers=BX.PopupWindowManager.create(null,this.layout.addUserToRole,{contentPadding:10,animation:"fading-slide",content:o,padding:0,offsetTop:5,angle:{position:"top",offset:35},autoHide:true,closeEsc:true,events:{onPopupShow:function(){setTimeout((function(){var e=o.querySelector(".ui-access-rights-popup-toggler-title-item");if(!e){return}e.classList.add("ui-access-rights-popup-toggler-title-item-active");r(e)}))},onPopupClose:function(){this.popupUsers.destroy();this.popupUsers=null}.bind(this)}})}return this.popupUsers},showUserSelectorPopup:function(){var e=BX.Main.selectorManagerV2.controls[this.popupContainer].selectorInstance;e.itemsSelected={};BX.onCustomEvent(this.openPopupEvent,[{id:this.popupContainer,bindNode:this.layout.addUserToRole}]);BX.onCustomEvent("BX.Main.SelectorV2:reInitDialog",[{selectorId:this.popupContainer,selectedItems:this.userGroup.accessCodes}])},adjustPopupHelper:function(){var e=this.layout.container.cloneNode(true);e.style.position="absolute";e.style.display="inline";e.style.height="0";document.body.appendChild(e);setTimeout((function(){e.parentNode.removeChild(e)}));if(e.offsetWidth>this.layout.container.offsetWidth){this.getPopupHelper().show()}},getPopupHelper:function(){if(!this.popupHelper){this.popupHelper=BX.PopupWindowManager.create(null,this.layout.container,{autoHide:true,darkMode:true,content:this.text,maxWidth:this.layout.container.offsetWidth,offsetTop:-9,offsetLeft:5,animation:"fading-slide"})}return this.popupHelper},render:function(){var e=this.getChanger();var t;if(this.type==="toggler"){t=this.getToggler();e.appendChild(t)}if(this.type==="variables"){t=this.getVariables();e.appendChild(t)}if(!this.layout.container){this.layout.container=BX.create("div",{props:{className:"ui-access-rights-column-item"},children:[this.type==="role"?this.getRole():null,this.type==="members"?this.getMembers():null,this.type==="title"?this.getTextNode():null,this.hint?this.getHint():null,this.type==="userGroupTitle"?this.getTextNode():null,this.controller?this.getController():null,this.type==="variables"||this.type==="toggler"?e:null]})}if(this.type==="role"&&this.column.newColumn){setTimeout(function(){this.onRoleEditMode();this.layout.roleInput.value=""}.bind(this))}return this.layout.container}}})();
//# sourceMappingURL=column.item.map.js